package mirrormonkey.core.tools.listeners;

import java.util.Deque;
import java.util.LinkedList;

import mirrormonkey.core.EntityLifecycleListener;
import mirrormonkey.framework.entity.StaticEntityData;
import mirrormonkey.framework.entity.SyncEntity;

public class MockEntityLifecycleListener implements EntityLifecycleListener {

	public final Deque<EntityLifecycleEvent> recordedEvents;

	public MockEntityLifecycleListener() {
		recordedEvents = new LinkedList<EntityLifecycleEvent>();
	}

	@Override
	public void entityInitialized(SyncEntity entity) {
		recordedEvents.add(new EntityInitializedEvent(entity));
	}

	@Override
	public void entityReplaced(SyncEntity replacedEntity,
			StaticEntityData replacedStaticData, SyncEntity replacingEntity) {
		recordedEvents.add(new EntityReplacedEvent(replacedEntity,
				replacedStaticData, replacingEntity));
	}

	@Override
	public void entityReplacing(SyncEntity replacedEntity,
			StaticEntityData replacedStaticData, SyncEntity replacingEntity) {
		recordedEvents.add(new EntityReplacingEvent(replacedEntity,
				replacedStaticData, replacingEntity));
	}

	@Override
	public void entityRemoved(SyncEntity entity) {
		recordedEvents.add(new EntityRemovedEvent(entity));
	}

	public static interface EntityLifecycleEvent {
	}

	public static class EntityInitializedEvent implements EntityLifecycleEvent {

		public final SyncEntity entity;

		public EntityInitializedEvent(SyncEntity entity) {
			this.entity = entity;
		}

	}

	public static class EntityReplacedEvent implements EntityLifecycleEvent {

		public final SyncEntity replacedEntity;

		public final StaticEntityData replacedStaticData;

		public final SyncEntity replacingEntity;

		public EntityReplacedEvent(SyncEntity replacedEntity,
				StaticEntityData replacedStaticData, SyncEntity replacingEntity) {
			this.replacedEntity = replacedEntity;
			this.replacedStaticData = replacedStaticData;
			this.replacingEntity = replacingEntity;
		}

	}

	public static class EntityReplacingEvent implements EntityLifecycleEvent {

		public final SyncEntity replacedEntity;

		public final StaticEntityData replacedStaticData;

		public final SyncEntity replacingEntity;

		public EntityReplacingEvent(SyncEntity replacedEntity,
				StaticEntityData replacedStaticData, SyncEntity replacingEntity) {
			this.replacedEntity = replacedEntity;
			this.replacedStaticData = replacedStaticData;
			this.replacingEntity = replacingEntity;
		}

	}

	public static class EntityRemovedEvent implements EntityLifecycleEvent {
		public final SyncEntity entity;

		public EntityRemovedEvent(SyncEntity entity) {
			this.entity = entity;
		}

	}
}
